package com.palfund.fragmentradiogroup;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class BlankFragment extends Fragment {

    private int mTabIndex;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mTabIndex = getArguments().getInt("tabIndex");
        Log.i("BlankFragment", "---onAttach()--->activity"+mTabIndex);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("BlankFragment", "---onCreate()--->"+mTabIndex+";当前fragment对象:"+this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
            savedInstanceState) {
        Log.i("BlankFragment", "---onCreateView()--->"+mTabIndex);
        return inflater.inflate(R.layout.fragment_blank, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        TextView textView= (TextView) view.findViewById(R.id.textView);
        String[] titles = getResources().getStringArray(R.array.arrTabTitles);
        textView.setText(titles[mTabIndex]);
        Log.i("BlankFragment", "---onViewCreated()--->"+mTabIndex);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.i("BlankFragment", "---onActivityCreated()--->"+mTabIndex);
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.i("BlankFragment", "---onStart()--->"+mTabIndex);
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i("BlankFragment", "---onResume()--->"+mTabIndex);
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i("BlankFragment", "---onPause()--->"+mTabIndex);
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.i("BlankFragment", "---onStop()--->"+mTabIndex);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.i("BlankFragment", "---onDestroyView()--->"+mTabIndex);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("BlankFragment", "---onDestroy()--->"+mTabIndex);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.i("BlankFragment", "---onDetach()--->"+mTabIndex);
    }

    /**
     * 创建Fragment传递参数
     *
     * @param tabIndex
     * @return
     */
    public static BlankFragment newInstance(int tabIndex) {
        BlankFragment fragment = new BlankFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("tabIndex", tabIndex);
        fragment.setArguments(bundle);
        return fragment;
    }

    public BlankFragment() {
    }
    //此方法在当前Fragment的显示、隐藏状态改变时调用
    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        Log.i("BlankFragment", "---onHiddenChanged()--->"+mTabIndex+";当前fragment对象:"+this);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Log.i("BlankFragment", "---onAttach()--->context"+mTabIndex);
    }

}
